<?php
class BodegaVehiculo extends AppModel {

	var $name = 'BodegaVehiculo';
	var $useTable = 'bodegas_vehiculos';
	var $validate = array(
		'bodega_id' => VALID_NOT_EMPTY,
		'vehiculo_id' => VALID_NOT_EMPTY,
		'fecha_asignada' => VALID_NOT_EMPTY,
	);

	function delBodega($bodega_id = null, $vehiculo_id = null, $fecha_asignada = null){
		$this->query("DELETE FROM bodegas_vehiculos WHERE bodega_id = $bodega_id AND vehiculo_id = $vehiculo_id AND fecha_asignada = '$fecha_asignada'");
		return true;
	}

	function getBodega($bodega_id = null, $vehiculo_id = null, $fecha_asignada = null)
	{
		$ret = $this->query("SELECT * FROM bodegas_vehiculos WHERE bodega_id = $bodega_id AND vehiculo_id = $vehiculo_id AND fecha_asignada = '$fecha_asignada'");
		return $this->adapt($ret);
	}

	function adapt($ret = null){
		$temp = $ret[0]['bodegas_vehiculos'];
		$data['BodegaVehiculo']['bodega_id'] = $temp['bodega_id'];
		$data['BodegaVehiculo']['vehiculo_id'] = $temp['vehiculo_id'];
		$data['BodegaVehiculo']['fecha_asignada'] = $temp['fecha_asignada'];
		return $data;
	}

	function saveBodega($data = null, $bodega_id = null, $vehiculo_id = null, $fecha_asignada = null){
		$bodega_id_new = $data['BodegaVehiculo']['bodega_id'];
		$vehiculo_id_new = $data['BodegaVehiculo']['vehiculo_id'];
		$fecha_asignada_new = $data['BodegaVehiculo']['fecha_asignada'];
		$this->query("UPDATE bodegas_vehiculos SET bodega_id = $bodega_id_new, vehiculo_id = $vehiculo_id_new, fecha_asignada = '$fecha_asignada_new' WHERE bodega_id = $bodega_id AND vehiculo_id = $vehiculo_id AND fecha_asignada = '$fecha_asignada'");
		return true;
	}

}
?>
